import { DataSchema } from './ajax'
import { ColumnsType } from 'antd/es/table'
import { Space, Divider } from 'antd'
import { Link } from 'react-router-dom'

export function getColumn (type: 'accepter' | 'processer' | 'manager', setVisible: (v: boolean) => void, setModifyData: (v: DataSchema) => void): ColumnsType<DataSchema> {
  const columns: ColumnsType<DataSchema> = [
    {
      title: '序号',
      dataIndex: 'orderno',
      key: 'orderno',
      width: 80
    },
    {
      title: '姓名',
      dataIndex: 'name',
      key: 'name'
    },
    {
      title: '办案权重',
      dataIndex: 'processer_case_weights',
      key: 'processer_case_weights',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(2)
        }
      },
      align: 'right'
    },
    {
      title: '办案分值',
      dataIndex: 'processer_case_score',
      key: 'processer_case_score',
      render: (v: number, l: DataSchema) => {
        if (typeof v === 'number') {
          return <Link to={`/admin/perfromance-case-list/${l.performanceid}?processer=${l.name}&type=办案`}>{v.toFixed(3)}</Link>
        }
      },
      align: 'right'
    },
    {
      title: '办案均值分',
      dataIndex: 'processer_ratio_score',
      key: 'processer_ratio_score',
      render: (v: number, l: DataSchema) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      },
      align: 'right'
    },
    {
      title: '撤裁/不予执行次数',
      dataIndex: 'dismissal_count',
      key: 'dismissal_count',
      align: 'right'
    },
    {
      title: '非办案权重',
      dataIndex: 'work_weights',
      key: 'work_weights',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(2)
        }
      },
      align: 'right'
    },
    {
      title: '非办案分值',
      dataIndex: 'work_score',
      key: 'work_score',
      render: (v: number, l: DataSchema) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      },
      align: 'right'
    },
    {
      title: type === 'manager' ? '总分' : '总分 / 除同期均值后总分',
      dataIndex: 'score',
      key: 'score',
      render: (v: number, l: DataSchema) => {
        const one = typeof v === 'number' ? v.toFixed(3) : '0'
        const two = typeof l.score_withratio === 'number' ? l.score_withratio.toFixed(3) : '0'
        if (type === 'manager') {
          return one
        }
        return `${one} / ${two}`
      },
      align: 'right'
    },
    {
      title: '操作',
      dataIndex: 'id',
      key: 'id',
      render: (v: string, l: DataSchema) => {
        return (
          <Space split={<Divider type='vertical' />}>
            <a onClick={() => { setModifyData(l); setVisible(true) }}>编辑</a>
          </Space>
        )
      }
    }
  ]
  if (type === 'accepter') {
    columns.splice(2, 0, {
      title: '受理权重',
      dataIndex: 'accepter_case_weights',
      key: 'accepter_case_weights',
      render: (v: number) => {
        if (typeof v === 'number') {
          return v.toFixed(2)
        }
      },
      align: 'right'
    }, {
      title: '受理分值',
      dataIndex: 'accepter_case_score',
      key: 'accepter_case_score',
      render: (v: number, l: DataSchema) => {
        if (typeof v === 'number') {
          return <Link to={`/admin/perfromance-case-list/${l.performanceid}?accepter=${l.name}&type=受理`}>{v.toFixed(3)}</Link>
        }
      },
      align: 'right'
    }, {
      title: '受理均值分',
      dataIndex: 'accepter_ratio_score',
      key: 'accepter_ratio_score',
      render: (v: number, l: DataSchema) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      },
      align: 'right'
    }, {
      title: '咨询次数',
      dataIndex: 'accepter_advise_count',
      key: 'accepter_advise_count',
      align: 'right'
    }, {
      title: '工作表现',
      dataIndex: 'accepter_case_coefficient',
      key: 'accepter_case_coefficient',
      render: (v: number, l: DataSchema) => {
        if (typeof v === 'number') {
          return v.toFixed(3)
        }
      },
      align: 'right'
    })
  }
  return columns
}
